package model;

import java.util.ArrayList;
import java.util.Scanner;

import service.Constan;
import service.EmployeeAPI;
import service.ProjectAPI;
import service.TimesheetAPI;
import service.implement.EmployeeDAO;
import service.implement.ProjectDAO;
import service.implement.TimesheetDAO;

public class Timesheet {
	private int id;
	private String date;
	private int duration;
	private String description;
	private String activity;
	private String overtime;
	private String location;
	private int employeeid;
	private int projectid;
	public Timesheet(){

	}
	public Timesheet(int id, String date, int duration, String description,
			String activity, String overtime, String location, int employeeid,
			int projectid) {
		super();
		this.id = id;
		this.date = date;
		this.duration = duration;
		this.description = description;
		this.activity = activity;
		this.overtime = overtime;
		this.location = location;
		this.employeeid = employeeid;
		this.projectid = projectid;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public int getDuration() {
		return duration;
	}
	public void setDuration(int duration) {
		this.duration = duration;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getActivity() {
		return activity;
	}
	public void setActivity(String activity) {
		this.activity = activity;
	}
	public String getOvertime() {
		return overtime;
	}
	public void setOvertime(String overtime) {
		this.overtime = overtime;
	}
	public String getLocation() {
		return location;
	}
	public void setLocation(String location) {
		this.location = location;
	}
	public int getEmployeeid() {
		return employeeid;
	}
	public void setEmployeeid(int employeeid) {
		this.employeeid = employeeid;
	}
	public int getProjectid() {
		return projectid;
	}
	public void setProjectid(int projectid) {
		this.projectid = projectid;
	}
	public Timesheet inputTimesheet() {
		TimesheetAPI tst=new TimesheetDAO();
		Scanner sc=new Scanner(System.in);
		ProjectAPI pj=new ProjectDAO();
		EmployeeAPI dao=new EmployeeDAO();
		System.out.println("==============Khai Timesheet===============");
		System.out.println("Enter Employeeid:");
		ArrayList<Employee> emps = dao.getEmployee();
		System.out.println(Constan.DISPLAY_EMP);
		for (Employee e:emps) {
			System.out.println("----------------------------------------------------------------------------------");
			System.out.println(e);
		}
		int employeeid=Integer.parseInt(sc.nextLine());
		if(!tst.checkEmployeeid(employeeid)){
			System.out.println("Employeeid khong hop le.Vui long thu lai");
			return null;
		}
		System.out.println("Enter Projectid:");
		ArrayList<Project> proj= pj.getProject();
		System.out.println(Constan.DISPLAY_PJ);
		for (Project p:proj) {
			System.out.println("--------------------------------------------------------------------------");
			System.out.println(p);
		}
		int projectid=Integer.parseInt(sc.nextLine());
		if(!tst.checkProjectid(projectid)){
			System.out.println("Projectid khong hop le.Vui long thu lai");
			return null;
		}
		System.out.println("Enter Date:(dd/mm/yyyy)");
		String date=sc.nextLine();
		if(!Constan.isValidDate(date)){
			System.out.println("Dinh dang date nhap vao k dung");
			return null;
		}
		System.out.println("Enter Duration");
		int duration=Integer.parseInt(sc.nextLine());
		System.out.println("Enter Description:");
		String description=sc.nextLine();
		System.out.println("Enter Activity:");
		String activity=sc.nextLine();
		System.out.println("Enter Overtime:");
		System.out.println("1. YES");
		System.out.println("2. NO");
		int a=Integer.parseInt(sc.nextLine());
		String overtime=tst.checkoverTime(a);
		System.out.println("Enter Location:");
		System.out.println("1.THNC");
		System.out.println("2.Ha Noi");
		System.out.println("3.HCM");
		int i=Integer.parseInt(sc.nextLine());
		String location=tst.checkLocation(i);
		Timesheet ts=new Timesheet(id,date,duration,description,activity,overtime,location,employeeid,projectid);
		return ts;
	}
	public Timesheet updateTimesheet() {
		TimesheetAPI ts=new TimesheetDAO();
		EmployeeAPI dao=new EmployeeDAO();
		ProjectAPI pj=new ProjectDAO();
		Scanner sc=new Scanner(System.in);
		System.out.println("Enter id you want update:");
		int id=Integer.parseInt(sc.nextLine());
		if(ts.getTimesheetById(id)==null){
			System.out.println("Id khong ton tai");
			return null;
		}
		else{
			System.out.println("Thong tin id da co:");
			System.out.println(Constan.DISPLAY_TS);
			Timesheet show=ts.getTimesheetById(id);
			System.out.println(show);
		}
		System.out.println("Enter Employeeid you want update:");
		ArrayList<Employee> emps = dao.getEmployee();
		System.out.println(Constan.DISPLAY_EMP);
		for (Employee e:emps) {
			System.out.println("----------------------------------------------------------------------------------");
			System.out.println(e);
		}
		int employeeid=Integer.parseInt(sc.nextLine());
		if(!ts.checkEmployeeid(employeeid)){
			System.out.println("Employeeid khong hop le.Vui long thu lai");
			employeeid=Integer.parseInt(sc.nextLine());
		}
		System.out.println("Enter Projectid you want update:");
		ArrayList<Project> proj= pj.getProject();
		System.out.println(Constan.DISPLAY_PJ);
		for (Project p:proj) {
			System.out.println("--------------------------------------------------------------------------");
			System.out.println(p);
		}
		int projectid=Integer.parseInt(sc.nextLine());
		if(!ts.checkProjectid(projectid)){
			System.out.println("Projectid khong hop le.Vui long thu lai");
			projectid=Integer.parseInt(sc.nextLine());
		}
		System.out.println("Enter date you want update:");
		String date=sc.nextLine();
		while(date.trim().equalsIgnoreCase("")){
			System.out.println("date chua duoc nhap.Nhap lai!");
			date=sc.nextLine();
		}
		System.out.println("Enter Duration you want update");
		int duration=Integer.parseInt(sc.nextLine());
		while(String.valueOf(duration).trim().equalsIgnoreCase("")){
			System.out.println("id chua duoc nhap.Nhap lai!");
			duration=Integer.parseInt(sc.nextLine());
		}
		System.out.println("Enter Description you want update:");
		String description=sc.nextLine();
		while(description.trim().equalsIgnoreCase("")){
			System.out.println("Description chua duoc nhap.Nhap lai!");
			description=sc.nextLine();
		}
		System.out.println("Enter Activity you want update:");
		String activity=sc.nextLine();
		while(activity.trim().equalsIgnoreCase("")){
			System.out.println("Activity chua duoc nhap.Nhap lai!");
			activity=sc.nextLine();
		}
		System.out.println("Enter Overtime you want update:");
		System.out.println("1. YES");
		System.out.println("2. NO");
		int a=Integer.parseInt(sc.nextLine());
		String overtime=ts.checkoverTime(a);
		System.out.println("Enter Location you want update:");
		System.out.println("1.THNC");
		System.out.println("2.Ha Noi");
		System.out.println("3.HCM");
		int i=Integer.parseInt(sc.nextLine());
		String location=ts.checkLocation(i);
		Timesheet tst=new Timesheet(id,date,duration,description,activity,overtime,location,employeeid,projectid);
		return tst;
	}
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "|"+getId() +"\t\t|"+getEmployeeid()+"\t\t|"+getProjectid()+"\t\t|" + getDate()+"\t\t|"+getDuration()+"\t\t\t|" +getDescription() +"\t\t|"+getActivity()+"\t\t|"+getOvertime()+"\t\t|"+getLocation();
	}
	

}
